package de.davvid.contracts;

import java.util.Date;

public class Contract {
	private Date begin, end;
	private int hours, recId;
	
	public Contract(Date begin, Date end, int hours) throws IllegalArgumentException {
		this(begin, end, hours, -1);
	}
	
	public Contract(Date begin, Date end, int hours, int recID) throws IllegalArgumentException {
		setBeginDate(begin);
		setEndDate(end);
		setHours(hours);
		this.recId = recID;
	}
	
	public Date getBeginDate() {
		return begin;
	}
	public Date getEndDate() {
		return end;
	}
	public int getHours() {
		return hours;
	}
	
	public int getRecId() {
		return recId;
	}
	
	public void setBeginDate(Date begin) throws IllegalArgumentException {
		if(begin.getTime() == 0) 
			throw new IllegalArgumentException("Please enter contract begin date.");
		else
			this.begin=begin;
	}
	
	public void setEndDate(Date end) throws IllegalArgumentException {
		if(end.getTime() == 0) 
			throw new IllegalArgumentException("Please enter contract end date.");
		else if(begin.getTime() >= end.getTime()) 
			throw new IllegalArgumentException("Contract duration is negative.");
		else 
			this.end = end;
	}
	
	public void setHours(int hours) throws IllegalArgumentException {
		if(hours <= 0 )
			throw new IllegalArgumentException("Please enter hours.");
		else
			this.hours = hours;
	}
	
	public void setRecId(int id) {
		this.recId = id;
	}
}
